#include <iostream>
#include <stdio.h>   //popen()
#include <sstream>

std::string execute(const std::string& cmd) {
  FILE *fp;
  char buffer[1024];
  memset(buffer, 0x00, sizeof(buffer));

  fp = popen(cmd.c_str(), "r");
  fgets(buffer, sizeof(buffer), fp);

  pclose(fp);
  return std::string(buffer);

}

std::string doubleToString(const double &val)
{
  char* chCode;
  chCode = new char[20];
  sprintf(chCode, "%.2lf%%", val*100);
  std::string str(chCode);
  delete[]chCode;
  return str;
}

int main()
{
//  std::string res;
//  res = execute("bash /Users/didi/CLionProjects/others/c++-ptn/d2_book/cpp_primer_cn/chap2/x86_pre_check.sh x86_conn_internet");
//  if (res.compare("1")) {
//    std::cout << "1" << res << std::endl;
//  }
  double s = 0.4957303955398766;
  std::cout << doubleToString(s);
  return 0;
}